﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace mana.Web.UI.WebControls
{
    public static class ListControlExtensions
    {
        public static void Load<T>(this ListControl control, IEnumerable<T> items, string textPropertyName, string valuePropetyName, bool hasEmptyItem, string emptyItemText)
        {
            control.Items.Clear();

            control.DataSource = items;
            control.DataTextField = textPropertyName;
            control.DataValueField = valuePropetyName;
            control.DataBind();

            if (hasEmptyItem)
                control.Items.Insert(0, new ListItem(emptyItemText, string.Empty));
        }
    }
}
